<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="类型:" prop="event_type.value">
                            <el-select v-model="queryParams.event_type.value" placeholder="请选择类型" clearable>
                                <el-option v-for="(item, index) in event_type" :key="index" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="周数:" prop="event_week.value">
                            <el-input v-model="queryParams.event_week.value" placeholder="请输入周数" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="大小标题:" prop="size_title.value">
                            <el-input v-model="queryParams.size_title.value" placeholder="请输入大小标题" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="状态:" prop="status.value">
                            <el-select v-model="queryParams.status.value" placeholder="请选择状态" clearable>
                                <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>


            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="180">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close append-to-body>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    props: {
        queryObj: {
            type: Object,
            default: ()=> {
                return {
                    event_type: ''
                }
            }
        }
    },
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60
                },
                {
                    visible: true,
                    label: '类型',
                    prop: 'event_type',
                    component:'QuickAdminTextColor',
                    width: 80,
                    formatter: (prop, row) => {
                        let type = ''
                        switch (prop) {
                            case 1:
                                type = 'success'
                                break
                            case 2:
                                type = 'warning'
                                break
                            case 3:
                                type = 'info'
                                break
                            case 4:
                                type = 'primary'
                                break

                        }
                        return {
                            value: prop,
                            type: type,
                            text: row.event_type_text,
                        }
                    },
                },
                {
                    visible: true,
                    label: '周数',
                    prop: 'event_week',
                    width: 80
                },
                {
                    visible: true,
                    label: '大小标题',
                    prop: 'size_title',
                    overflow: true
                },
                // {
                //     visible: true,
                //     label: '头臀径',
                //     prop: 'size_toutun',
                // },
                // {
                //     visible: true,
                //     label: '胎重',
                //     prop: 'size_taizhong',
                // },
                // {
                //     visible: true,
                //     label: '身长',
                //     prop: 'size_shenchang',
                // },
                // {
                //     visible: true,
                //     label: '双顶径',
                //     prop: 'size_shuangding',
                // },
                // {
                //     visible: true,
                //     label: '股骨长',
                //     prop: 'size_gugu',
                // },
                // {
                //     visible: true,
                //     label: '头围',
                //     prop: 'size_touwei',
                // },
                // {
                //     visible: true,
                //     label: '腹围',
                //     prop: 'size_fuwei',
                // },
                // {
                //     visible: true,
                //     label: '体重男',
                //     prop: 'size_tizhong_nan',
                // },
                // {
                //     visible: true,
                //     label: '体重女',
                //     prop: 'size_tizhong_nv',
                // },
                // {
                //     visible: true,
                //     label: '身高男 ',
                //     prop: 'size_shengao_nan',
                // },
                // {
                //     visible: true,
                //     label: '身高女',
                //     prop: 'size_shengao_nv',
                // },
                {
                    visible: true,
                    label: '状态',
                    prop: 'status',
                    component:'QuickAdminTextColor',
                    width: 80,
                    formatter: (prop, row) => {
                        let type = ''
                        switch (prop) {
                            case 1:
                                type = 'success'
                                break
                            case 2:
                                type = 'warning'
                                break

                        }
                        return {
                            value: prop,
                            type: type,
                            text: row.status_text,
                        }
                    },
                },
                {
                    visible: true,
                    label: '创建日期',
                    prop: 'create_time',
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                },

            ],
            // 接口地址
            api: {
                index: `/admin/sq.user_event_remind_size/index`,
                find: `/admin/sq.user_event_remind_size/find`,
                add: `/admin/sq.user_event_remind_size/add`,
                edit: `/admin/sq.user_event_remind_size/edit`,
                delete: `/admin/sq.user_event_remind_size/delete`,
                export: `/admin/sq.user_event_remind_size/export`,
                status: `/admin/sq.user_event_remind_size/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                event_type: { value:undefined, op: '='},
                event_week: { value:undefined, op: '='},
                size_title: { value:undefined, op: '%like%'},
                status: { value:undefined, op: '='},
            },
            event_type:[
               { label: "记经期", value: 1 },
               { label: "备孕中", value: 2 },
               { label: "已怀孕", value: 3 },
               { label: "已出生", value: 4 },
            ],
            status:[
               { label: "启用", value: 1 },
               { label: "禁用", value: 2 },
            ],
            tableIsJoinLoad: false
        }
    },
    created() {
        if (this.queryObj.event_type) {
            this.$set(this.queryParams.event_type, 'value', this.queryObj.event_type)
            this.columns[1].visible = false
        }
        this.initIndex()
    }
}
</script>
